from CloudEngine.Render.State import AppState
from CloudEngine.core.VTActor import VTActor


class UserInputMod:
    app = None
    selector = None

    def __init__(self, app, selector):
        self.app = app
        self.selector = selector

    def right_button_press(self, x, y):
        match self.app.state.get_current_state():
            case AppState.NORMAL:
                self.handle_for_normal_mode(x, y)

    def handle_for_normal_mode(self, x, y):
        cell_index = self.selector.pickCell(x, y)
        if cell_index == -1:
            return
        ac: VTActor = self.selector.getPickedVTActors()[0]
        if self.app.state.is_cell_selected(cell_index):
            self.app.state.remove_select_cell(cell_index)
            ac.set_cells_color([cell_index], ac.default_color)
        else:
            self.app.state.add_select_cell({"cell_index": cell_index})
            ac.set_cells_color([cell_index], [0, 255, 0, 255])

        self.app.render()
